﻿using System;
using System.Collections.Generic;

namespace ToyStore.Domain.Common
{
    /// <summary>
    /// Klasa z rozszerzeniami innych elementów języka.
    /// </summary>
	public static class Extensions
	{
        /// <summary>
        /// Dodanie metody AddRange do IListy.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="list"></param>
        /// <param name="items"></param>
		public static void AddRange<T>(this IList<T> list, IEnumerable<T> items)
		{
			if (list == null) throw new ArgumentNullException("list");
			if (items == null) throw new ArgumentNullException("items");
			foreach (T item in items) list.Add(item);
		}

		/// <summary>
		/// Foreach :D
		/// </summary>
		/// <typeparam name="T"></typeparam>
		/// <param name="source"></param>
		/// <param name="action"></param>
		public static void ForEach<T>(this IEnumerable<T> source, Action<T> action)
		{
			if (source == null) throw new ArgumentNullException("source");
			if (action == null) throw new ArgumentNullException("action");

			foreach (T item in source)
			{
				action(item);
			}
		}
	}
}
